package com.wgcloud.entity;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

public class ResponseUtil {

    // 创建成功的ResponseEntity
    public static <T> ResponseEntity<Result<T>> success(T data) {
        Result<T> result = Result.success(data);
        return new ResponseEntity<>(result, HttpStatus.OK);
    }

    // 创建失败的ResponseEntity
    public static <T> ResponseEntity<Result<T>> error(int code, String msg) {
        Result<T> result = Result.error(code, msg);
        return new ResponseEntity<>(result, HttpStatus.INTERNAL_SERVER_ERROR);
    }

    // 创建自定义状态码的ResponseEntity
    public static <T> ResponseEntity<Result<T>> custom(int code, String msg, T data, HttpStatus status) {
        Result<T> result = new Result<>(code, msg, data);
        return new ResponseEntity<>(result, status);
    }
}